package com.lonewalker.sparrow.util;


import com.lonewalker.sparrow.exception.ServiceException;

/**
 * 业务断言  条件为真时抛异常
 * @author lonewalker
 */
public class BizAssert {

    /**
     * 条件为真，抛业务异常
     *
     * @param expression 条件
     * @param msg        异常信息
     */
    public static void throwServiceError(boolean expression, String msg) {
        if (expression) {
            throw new ServiceException(msg);
        }
    }

    /**
     * 条件为真，抛业务异常
     *
     * @param expression 条件
     * @param code 异常code
     * @param msg 异常信息
     */
    public static void throwServiceError(boolean expression, Integer code, String msg) {
        if (expression) {
            throw new ServiceException(code,msg);
        }
    }

}
